package com.web.core.base.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.blue.core.dict.State;
import com.blue.jdbc.JdbcDataSource;
import com.blue.jdbc.Page;
import com.web.core.base.dao.ConfigDao;
import com.web.core.base.model.Config;
import com.web.core.util.Const;
import com.web.core.util.WebException;

@Service
@Transactional
@JdbcDataSource(Const.DS_BASE)
public class ConfigService
{
	@Resource
	private ConfigDao configDao;
	
	public ConfigService()
	{
	}
	
	
	public void save(Config config)
	{
		if (configDao.exist(config, "key"))
			throw new WebException("配置已经存在：" + config.getKey());
		
		if (config.getId() == null)
		{
			configDao.save(config);
		}
		else
		{
			configDao.update(config);
		}
	}
	
	
	public void delete(Config config)
	{
		configDao.delete(config);
	}
	
	
	public Page<Config> list(Config config, Page<Config> page)
	{
		page = configDao.list(config, page);
		return page;
	}
	
	public List<Config> list()
	{
		Config config = new Config();
		config.setState(State.NORMAL);
		return configDao.list(config);
	}
	
	public Config get(Integer id)
	{
		return configDao.get(id);
	}
}
